﻿namespace CnblogReader
{
    using Microsoft.Phone.Controls;
    using System.ComponentModel;
    using System.Windows.Controls.Primitives;
    using Microsoft.Phone.Shell;
    using System.Threading;

    public partial class MainPage : PhoneApplicationPage
    {
        private BackgroundWorker backroungWorker;
        private Popup myPopup;  

        // Constructor
        public MainPage()
        {
            InitializeComponent();
            myPopup = new Popup() { IsOpen = true, Child = new SplashScreen() };

            backroungWorker = new BackgroundWorker();
            RunBackgroundWorker();
            this.SetValue(SystemTray.IsVisibleProperty, false);
        }

        private void RunBackgroundWorker()
        {
            backroungWorker.DoWork += ((s, args) =>
            {
                Thread.Sleep(3000);
            });

            backroungWorker.RunWorkerCompleted += ((s, args) =>
            {
                this.Dispatcher.BeginInvoke(() =>
                {
                    this.myPopup.IsOpen = false;
                });
            });

            backroungWorker.RunWorkerAsync();
        }
    }
}